package cn.wokoba.trigger.ExceptionHandler;

import cn.wokoba.types.enums.ResponseCode;
import cn.wokoba.types.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 未捕获的未知异常
     *
     * @param ex
     * @return
     */
    @ExceptionHandler
    public Response<String> exceptionHandler(Exception ex) {
        log.error("未知异常信息：", ex);
        return Response.<String>builder()
                .code(ResponseCode.UN_ERROR.getCode())
                .info(ResponseCode.UN_ERROR.getInfo())
                .build();
    }
}
